﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessTier
{
    public class MazeServerFactory
    {
        private static IDictionary<string, MazeServer> games = new Dictionary<string, MazeServer>();

        /// <summary>
        /// Accepts some kind of game server identifier (that uniquely 
        /// identifies a particular active game that is known to the 
        /// underlying data tier) and constructs an exact replica of the 
        /// current server instance.
        /// </summary>
        /// <returns></returns>
        public static MazeServer getMazeServer(string key)
        {
            if (games.ContainsKey(key))
            {
                return games[key];
            }
            else
            {
                return null;
            }
        }

        public static string createMazeServer()
        {
            string gameUid = Guid.NewGuid().ToString("N");
            games.Add(gameUid, new MazeServer(gameUid));
            return gameUid;
        }

        public static void deleteMazeServer(string key)
        {
            if (games.ContainsKey(key))
            {
                games.Remove(key);
            }
        }
    }
}
